/**
 * 地理信息数据
 * 包含省市区县村庄的完整地理信息
 */

// 省份数据
export const provinces = [
  { name: '河南省', code: '41' },
  { name: '山东省', code: '37' },
  { name: '河北省', code: '13' },
  { name: '山西省', code: '14' },
  { name: '江苏省', code: '32' },
  { name: '安徽省', code: '34' },
  { name: '浙江省', code: '33' },
  { name: '福建省', code: '35' },
  { name: '江西省', code: '36' },
  { name: '湖北省', code: '42' },
  { name: '湖南省', code: '43' },
  { name: '广东省', code: '44' },
  { name: '广西壮族自治区', code: '45' },
  { name: '海南省', code: '46' },
  { name: '四川省', code: '51' },
  { name: '贵州省', code: '52' },
  { name: '云南省', code: '53' },
  { name: '西藏自治区', code: '54' },
  { name: '陕西省', code: '61' },
  { name: '甘肃省', code: '62' },
  { name: '青海省', code: '63' },
  { name: '宁夏回族自治区', code: '64' },
  { name: '新疆维吾尔自治区', code: '65' },
  { name: '内蒙古自治区', code: '15' },
  { name: '辽宁省', code: '21' },
  { name: '吉林省', code: '22' },
  { name: '黑龙江省', code: '23' },
  { name: '北京市', code: '11' },
  { name: '天津市', code: '12' },
  { name: '上海市', code: '31' },
  { name: '重庆市', code: '50' }
]

// 城市数据
export const citiesData = {
  '河南省': [
    { name: '郑州市', code: '410100' },
    { name: '开封市', code: '410200' },
    { name: '洛阳市', code: '410300' },
    { name: '平顶山市', code: '410400' },
    { name: '安阳市', code: '410500' },
    { name: '鹤壁市', code: '410600' },
    { name: '新乡市', code: '410700' },
    { name: '焦作市', code: '410800' },
    { name: '濮阳市', code: '410900' },
    { name: '许昌市', code: '411000' },
    { name: '漯河市', code: '411100' },
    { name: '三门峡市', code: '411200' },
    { name: '南阳市', code: '411300' },
    { name: '商丘市', code: '411400' },
    { name: '信阳市', code: '411500' },
    { name: '周口市', code: '411600' },
    { name: '驻马店市', code: '411700' },
    { name: '济源市', code: '419001' }
  ],
  '山东省': [
    { name: '济南市', code: '370100' },
    { name: '青岛市', code: '370200' },
    { name: '淄博市', code: '370300' },
    { name: '枣庄市', code: '370400' },
    { name: '东营市', code: '370500' },
    { name: '烟台市', code: '370600' },
    { name: '潍坊市', code: '370700' },
    { name: '济宁市', code: '370800' },
    { name: '泰安市', code: '370900' },
    { name: '威海市', code: '371000' },
    { name: '日照市', code: '371100' },
    { name: '临沂市', code: '371300' },
    { name: '德州市', code: '371400' },
    { name: '聊城市', code: '371500' },
    { name: '滨州市', code: '371600' },
    { name: '菏泽市', code: '371700' }
  ],
  '河北省': [
    { name: '石家庄市', code: '130100' },
    { name: '唐山市', code: '130200' },
    { name: '秦皇岛市', code: '130300' },
    { name: '邯郸市', code: '130400' },
    { name: '邢台市', code: '130500' },
    { name: '保定市', code: '130600' },
    { name: '张家口市', code: '130700' },
    { name: '承德市', code: '130800' },
    { name: '沧州市', code: '130900' },
    { name: '廊坊市', code: '131000' },
    { name: '衡水市', code: '131100' }
  ],
  '山西省': [
    { name: '太原市', code: '140100' },
    { name: '大同市', code: '140200' },
    { name: '阳泉市', code: '140300' },
    { name: '长治市', code: '140400' },
    { name: '晋城市', code: '140500' },
    { name: '朔州市', code: '140600' },
    { name: '晋中市', code: '140700' },
    { name: '运城市', code: '140800' },
    { name: '忻州市', code: '140900' },
    { name: '临汾市', code: '141000' },
    { name: '吕梁市', code: '141100' }
  ],
  '江苏省': [
    { name: '南京市', code: '320100' },
    { name: '无锡市', code: '320200' },
    { name: '徐州市', code: '320300' },
    { name: '常州市', code: '320400' },
    { name: '苏州市', code: '320500' },
    { name: '南通市', code: '320600' },
    { name: '连云港市', code: '320700' },
    { name: '淮安市', code: '320800' },
    { name: '盐城市', code: '320900' },
    { name: '扬州市', code: '321000' },
    { name: '镇江市', code: '321100' },
    { name: '泰州市', code: '321200' },
    { name: '宿迁市', code: '321300' }
  ],
  '湖南省': [
    { name: '长沙市', code: '430100' },
    { name: '株洲市', code: '430200' },
    { name: '湘潭市', code: '430300' },
    { name: '衡阳市', code: '430400' },
    { name: '邵阳市', code: '430500' },
    { name: '岳阳市', code: '430600' },
    { name: '常德市', code: '430700' },
    { name: '张家界市', code: '430800' },
    { name: '益阳市', code: '430900' },
    { name: '郴州市', code: '431000' },
    { name: '永州市', code: '431100' },
    { name: '怀化市', code: '431200' },
    { name: '娄底市', code: '431300' },
    { name: '湘西土家族苗族自治州', code: '433100' }
  ]
}

// 县区数据
export const countiesData = {
  '新乡市': [
    { name: '红旗区', code: '410702' },
    { name: '卫滨区', code: '410703' },
    { name: '凤泉区', code: '410704' },
    { name: '牧野区', code: '410711' },
    { name: '新乡县', code: '410721' },
    { name: '获嘉县', code: '410724' },
    { name: '原阳县', code: '410725' },
    { name: '延津县', code: '410726' },
    { name: '封丘县', code: '410727' },
    { name: '长垣市', code: '410728' },
    { name: '卫辉市', code: '410781' },
    { name: '辉县市', code: '410782' }
  ],
  '郑州市': [
    { name: '中原区', code: '410102' },
    { name: '二七区', code: '410103' },
    { name: '管城回族区', code: '410104' },
    { name: '金水区', code: '410105' },
    { name: '上街区', code: '410106' },
    { name: '惠济区', code: '410108' },
    { name: '中牟县', code: '410122' },
    { name: '巩义市', code: '410181' },
    { name: '荥阳市', code: '410182' },
    { name: '新密市', code: '410183' },
    { name: '新郑市', code: '410184' },
    { name: '登封市', code: '410185' }
  ],
  '济南市': [
    { name: '历下区', code: '370102' },
    { name: '市中区', code: '370103' },
    { name: '槐荫区', code: '370104' },
    { name: '天桥区', code: '370105' },
    { name: '历城区', code: '370112' },
    { name: '长清区', code: '370113' },
    { name: '章丘区', code: '370114' },
    { name: '平阴县', code: '370124' },
    { name: '济阳区', code: '370115' },
    { name: '商河县', code: '370126' }
  ],
  '青岛市': [
    { name: '市南区', code: '370202' },
    { name: '市北区', code: '370203' },
    { name: '黄岛区', code: '370211' },
    { name: '崂山区', code: '370212' },
    { name: '李沧区', code: '370213' },
    { name: '城阳区', code: '370214' },
    { name: '即墨区', code: '370215' },
    { name: '胶州市', code: '370281' },
    { name: '平度市', code: '370283' },
    { name: '莱西市', code: '370285' }
  ],
  '石家庄市': [
    { name: '长安区', code: '130102' },
    { name: '桥西区', code: '130104' },
    { name: '新华区', code: '130105' },
    { name: '井陉矿区', code: '130107' },
    { name: '裕华区', code: '130108' },
    { name: '藁城区', code: '130109' },
    { name: '鹿泉区', code: '130110' },
    { name: '栾城区', code: '130111' },
    { name: '井陉县', code: '130121' },
    { name: '正定县', code: '130123' },
    { name: '行唐县', code: '130125' },
    { name: '灵寿县', code: '130126' },
    { name: '高邑县', code: '130127' },
    { name: '深泽县', code: '130128' },
    { name: '赞皇县', code: '130129' },
    { name: '无极县', code: '130130' },
    { name: '平山县', code: '130131' },
    { name: '元氏县', code: '130132' },
    { name: '赵县', code: '130133' },
    { name: '辛集市', code: '130181' },
    { name: '晋州市', code: '130183' },
    { name: '新乐市', code: '130184' }
  ],
  '太原市': [
    { name: '小店区', code: '140105' },
    { name: '迎泽区', code: '140106' },
    { name: '杏花岭区', code: '140107' },
    { name: '尖草坪区', code: '140108' },
    { name: '万柏林区', code: '140109' },
    { name: '晋源区', code: '140110' },
    { name: '清徐县', code: '140121' },
    { name: '阳曲县', code: '140122' },
    { name: '娄烦县', code: '140123' },
    { name: '古交市', code: '140181' }
  ],
  '南京市': [
    { name: '玄武区', code: '320102' },
    { name: '秦淮区', code: '320104' },
    { name: '建邺区', code: '320105' },
    { name: '鼓楼区', code: '320106' },
    { name: '浦口区', code: '320111' },
    { name: '栖霞区', code: '320113' },
    { name: '雨花台区', code: '320114' },
    { name: '江宁区', code: '320115' },
    { name: '六合区', code: '320116' },
    { name: '溧水区', code: '320117' },
    { name: '高淳区', code: '320118' }
  ],
  '长沙市': [
    { name: '芙蓉区', code: '430102' },
    { name: '天心区', code: '430103' },
    { name: '岳麓区', code: '430104' },
    { name: '开福区', code: '430105' },
    { name: '雨花区', code: '430111' },
    { name: '望城区', code: '430112' },
    { name: '长沙县', code: '430121' },
    { name: '宁乡市', code: '430182' },
    { name: '浏阳市', code: '430181' }
  ],
  '株洲市': [
    { name: '荷塘区', code: '430202' },
    { name: '芦淞区', code: '430203' },
    { name: '石峰区', code: '430204' },
    { name: '天元区', code: '430211' },
    { name: '渌口区', code: '430212' },
    { name: '攸县', code: '430223' },
    { name: '茶陵县', code: '430224' },
    { name: '炎陵县', code: '430225' },
    { name: '醴陵市', code: '430281' }
  ],
  '湘潭市': [
    { name: '雨湖区', code: '430302' },
    { name: '岳塘区', code: '430304' },
    { name: '湘潭县', code: '430321' },
    { name: '湘乡市', code: '430381' },
    { name: '韶山市', code: '430382' }
  ],
  '衡阳市': [
    { name: '珠晖区', code: '430405' },
    { name: '雁峰区', code: '430406' },
    { name: '石鼓区', code: '430407' },
    { name: '蒸湘区', code: '430408' },
    { name: '南岳区', code: '430412' },
    { name: '衡阳县', code: '430421' },
    { name: '衡南县', code: '430422' },
    { name: '衡山县', code: '430423' },
    { name: '衡东县', code: '430424' },
    { name: '祁东县', code: '430426' },
    { name: '耒阳市', code: '430481' },
    { name: '常宁市', code: '430482' }
  ],
  '邵阳市': [
    { name: '双清区', code: '430502' },
    { name: '大祥区', code: '430503' },
    { name: '北塔区', code: '430511' },
    { name: '邵东市', code: '430521' },
    { name: '新邵县', code: '430522' },
    { name: '邵阳县', code: '430523' },
    { name: '隆回县', code: '430524' },
    { name: '洞口县', code: '430525' },
    { name: '绥宁县', code: '430527' },
    { name: '新宁县', code: '430528' },
    { name: '城步苗族自治县', code: '430529' },
    { name: '武冈市', code: '430581' }
  ],
  '岳阳市': [
    { name: '岳阳楼区', code: '430602' },
    { name: '云溪区', code: '430603' },
    { name: '君山区', code: '430611' },
    { name: '岳阳县', code: '430621' },
    { name: '华容县', code: '430623' },
    { name: '湘阴县', code: '430624' },
    { name: '平江县', code: '430626' },
    { name: '汨罗市', code: '430681' },
    { name: '临湘市', code: '430682' }
  ],
  '常德市': [
    { name: '武陵区', code: '430702' },
    { name: '鼎城区', code: '430703' },
    { name: '安乡县', code: '430721' },
    { name: '汉寿县', code: '430722' },
    { name: '澧县', code: '430723' },
    { name: '临澧县', code: '430724' },
    { name: '桃源县', code: '430725' },
    { name: '石门县', code: '430726' },
    { name: '津市市', code: '430781' }
  ],
  '张家界市': [
    { name: '永定区', code: '430802' },
    { name: '武陵源区', code: '430811' },
    { name: '慈利县', code: '430821' },
    { name: '桑植县', code: '430822' }
  ],
  '益阳市': [
    { name: '资阳区', code: '430902' },
    { name: '赫山区', code: '430903' },
    { name: '南县', code: '430921' },
    { name: '桃江县', code: '430922' },
    { name: '安化县', code: '430923' },
    { name: '沅江市', code: '430981' }
  ],
  '郴州市': [
    { name: '北湖区', code: '431002' },
    { name: '苏仙区', code: '431003' },
    { name: '桂阳县', code: '431021' },
    { name: '宜章县', code: '431022' },
    { name: '永兴县', code: '431023' },
    { name: '嘉禾县', code: '431024' },
    { name: '临武县', code: '431025' },
    { name: '汝城县', code: '431026' },
    { name: '桂东县', code: '431027' },
    { name: '安仁县', code: '431028' },
    { name: '资兴市', code: '431081' }
  ],
  '永州市': [
    { name: '零陵区', code: '431102' },
    { name: '冷水滩区', code: '431103' },
    { name: '祁阳县', code: '431121' },
    { name: '东安县', code: '431122' },
    { name: '双牌县', code: '431123' },
    { name: '道县', code: '431124' },
    { name: '江永县', code: '431125' },
    { name: '宁远县', code: '431126' },
    { name: '蓝山县', code: '431127' },
    { name: '新田县', code: '431128' },
    { name: '江华瑶族自治县', code: '431129' }
  ],
  '怀化市': [
    { name: '鹤城区', code: '431202' },
    { name: '中方县', code: '431221' },
    { name: '沅陵县', code: '431222' },
    { name: '辰溪县', code: '431223' },
    { name: '溆浦县', code: '431224' },
    { name: '会同县', code: '431225' },
    { name: '麻阳苗族自治县', code: '431226' },
    { name: '新晃侗族自治县', code: '431227' },
    { name: '芷江侗族自治县', code: '431228' },
    { name: '靖州苗族侗族自治县', code: '431229' },
    { name: '通道侗族自治县', code: '431230' },
    { name: '洪江市', code: '431281' }
  ],
  '娄底市': [
    { name: '娄星区', code: '431302' },
    { name: '双峰县', code: '431321' },
    { name: '新化县', code: '431322' },
    { name: '冷水江市', code: '431381' },
    { name: '涟源市', code: '431382' }
  ]
}

// 村庄数据
export const villagesData = {
  '新乡县': [
    { name: '七里营村', code: '410721001' },
    { name: '小冀镇', code: '410721002' },
    { name: '古固寨镇', code: '410721003' },
    { name: '朗公庙镇', code: '410721004' },
    { name: '大召营镇', code: '410721005' }
  ],
  '获嘉县': [
    { name: '城关镇', code: '410724001' },
    { name: '照镜镇', code: '410724002' },
    { name: '黄堤镇', code: '410724003' },
    { name: '中和镇', code: '410724004' },
    { name: '徐营镇', code: '410724005' }
  ],
  '芙蓉区': [
    { name: '韭菜园街道', code: '430102001' },
    { name: '文艺路街道', code: '430102002' },
    { name: '朝阳街街道', code: '430102003' },
    { name: '五里牌街道', code: '430102004' },
    { name: '火星街道', code: '430102005' }
  ],
  '天心区': [
    { name: '坡子街街道', code: '430103001' },
    { name: '城南路街道', code: '430103002' },
    { name: '裕南街街道', code: '430103003' },
    { name: '金盆岭街道', code: '430103004' },
    { name: '新开铺街道', code: '430103005' }
  ],
  '岳麓区': [
    { name: '望月湖街道', code: '430104001' },
    { name: '岳麓街道', code: '430104002' },
    { name: '桔子洲街道', code: '430104003' },
    { name: '银盆岭街道', code: '430104004' },
    { name: '观沙岭街道', code: '430104005' }
  ],
  '开福区': [
    { name: '芙蓉北路街道', code: '430105001' },
    { name: '东风路街道', code: '430105002' },
    { name: '清水塘街道', code: '430105003' },
    { name: '湘雅路街道', code: '430105004' },
    { name: '伍家岭街道', code: '430105005' }
  ],
  '雨花区': [
    { name: '左家塘街道', code: '430111001' },
    { name: '侯家塘街道', code: '430111002' },
    { name: '东塘街道', code: '430111003' },
    { name: '砂子塘街道', code: '430111004' },
    { name: '圭塘街道', code: '430111005' }
  ]
}

// 工具函数
export const geoUtils = {
  /**
   * 根据省份名称获取城市列表
   * @param {string} provinceName 省份名称
   * @returns {Array} 城市列表
   */
  getCitiesByProvince(provinceName) {
    return citiesData[provinceName] || []
  },

  /**
   * 根据城市名称获取县区列表
   * @param {string} cityName 城市名称
   * @returns {Array} 县区列表
   */
  getCountiesByCity(cityName) {
    return countiesData[cityName] || []
  },

  /**
   * 根据县区名称获取村庄列表
   * @param {string} countyName 县区名称
   * @returns {Array} 村庄列表
   */
  getVillagesByCounty(countyName) {
    return villagesData[countyName] || []
  },

  /**
   * 根据代码查找地区名称
   * @param {string} code 地区代码
   * @returns {Object|null} 地区信息
   */
  findRegionByCode(code) {
    // 查找省份
    for (const province of provinces) {
      if (province.code === code) {
        return { type: 'province', ...province }
      }
    }

    // 查找城市
    for (const [provinceName, cities] of Object.entries(citiesData)) {
      for (const city of cities) {
        if (city.code === code) {
          return { type: 'city', ...city, province: provinceName }
        }
      }
    }

    // 查找县区
    for (const [cityName, counties] of Object.entries(countiesData)) {
      for (const county of counties) {
        if (county.code === code) {
          return { type: 'county', ...county, city: cityName }
        }
      }
    }

    // 查找村庄
    for (const [countyName, villages] of Object.entries(villagesData)) {
      for (const village of villages) {
        if (village.code === code) {
          return { type: 'village', ...village, county: countyName }
        }
      }
    }

    return null
  }
}
